package persistenceAndSerialization;

import java.io.IOException;
import java.util.List;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;



public class JDomEvaluate {
	public static void main(String[] args) {
		SAXBuilder builder=new SAXBuilder();
		try {
			Document ducument = builder.build("sample.xml");
			Element root = ducument.getRootElement();
			List<Element> children = root.getChildren();
			//child:major,student
			for(Element child:children){
				if(!"student".equals(child.getName())){
					continue;
				}
				System.out.println("------student-----");
				System.out.println("id:"+child.getAttributeValue("id"));
				System.out.println("name:"+child.getChildText("name"));
				System.out.println("gender:"+child.getChildText("gender"));
				System.out.println("age:"+child.getChildText("age"));
			}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
